<template>
	<view>
		<navbar  title="商家信息" :isGoBack="true" :isNotice="true" ></navbar>		
		<view class="pt-30 flex justify-around" style="background: #fff;">
		  <view class="main_tag" style="background: #2B91ED;margin-right: 10rpx;" @click.stop="checkbox(1)"><text>全选</text></view>
		  <view class="main_tag" style="background: #2B91ED;" @click.stop="checkbox(2)"><text>取消</text></view>
		</view>
		<view  class="all_shop">
		    <view class="all_shop_check"  v-for="(item,index)  in shopList" :key="index">
		      <radio color="#2B91ED" :checked="item.check"   @click="radioChange(item.id)"></radio>
		      <text>{{item.storage_shop_name}}</text>
		    </view>
		</view>
		<view class="flex">
			<button @click="!loading?formSubmit():''"><u-loading-icon color="#fff" size="16" style="margin-right: 5rpx;" :show="loading"></u-loading-icon> 提交</button>
		</view>			
	</view>
</template>

<script>
	export default {
		data () {
			return {
				shopList:[],
				loading:false
			}			
		},
		onShow() {
		    this.doSelectShop()
		},
		methods:{			
			doSelectShop(){
			    this.$http.doShopList().then(res=>{
			        if(res.resCode=='9999'){
			          this.shopList=res.data
			        }
			    })
			},
			  //全选处理
			  checkbox(type) {
			   
			    let shopList=this.shopList 
			    if(type==1){        
			      for (let i = 0; i < shopList.length; i++) {  
			        shopList[i].check=true        
			      } 
			    } else {
			      for (let i = 0; i < shopList.length; i++) {  
			        shopList[i].check=false        
			      }
			    }
				console.log(shopList)
			    this.shopList=shopList
			  },
			
			radioChange(index){	
			    let shopList=this.shopList 
			    for (let i = 0; i < shopList.length; i++) {  
			      if(shopList[i].id==index){
			        if(shopList[i].check)  shopList[i].check=false;
			        else  shopList[i].check=true;
			      }  
			    } 
			    this.shopList=shopList
			},
			
			formSubmit(){
				let shopList=this.shopList
				
				console.log('shopList',shopList)
				let storageId=[]
				for(let i=0; i<shopList.length;i++){
				  if(shopList[i].check){
					storageId.push(shopList[i].id)
				  }
				}
				if(storageId.length<=0){
				  uni.showToast({title:"请选择商家信息！",icon:"none"})
				  return
				}
				
			    this.$http.doorderSend({
				  token:uni.getStorageSync('userInfo').app_openid,
				  login_type:'app',
				  storageId:JSON.stringify(storageId)
				}).then(res=>{
				   if(res.resCode=="9999"){			
					uni.showToast({title:res.resMessage,icon:"none"})
					setTimeout(function () {
					  //要延时执行的代码
						uni.navigateTo({
						  url: '/pages/pagesuser/shopgoods/index',
						  success: function (e) {
							let pages = getCurrentPages()
							let currPage = pages[pages.length-2] //当前页面B页面实例
							currPage.$vm.refresh() //调用A页面的refresh方法
						  }
					   })
					}, 1500) //延迟时间
			
				   }else{
					uni.showToast({title:res.resMessage,icon:"none"})
				   }
				})					
			}

		}
	}
</script>

<style>
	/* pagesOrder/dispatch/index.wxss */
	.all_shop{
	    display: flex;
	    flex-direction: row;
	    flex-wrap: wrap;
	    background-color: #fff;
	   
	}
	
	.all_shop_check{
	  display: flex;
	  flex-direction: row;
	  width: 50%;
	  margin-top: 20rpx;
	  margin-bottom: 20rpx;
	}
	
	.main_tag{
	  
	  display: flex;
	  color: white;
	  width: 100rpx;
	  height: 56rpx;
	  font-size: 20rpx;
	  align-items: center;
	  vertical-align: center;
	  justify-content: center;
	  border-radius: 5rpx;
	
	}
	
	button{
	display: flex;
	flex-direction: row;
	justify-content: center;
	color: white;
	border: none;
	width: 85%;
	padding: 5rpx 0rpx;
	position: absolute; /* 设置按钮为绝对定位 */
	bottom: 0; /* 距离底边为0 */
	left: 50%; /* 左侧距离父元素宽度的50% */
	transform: translateX(-50%); /* 向左移动自身宽度的50%，保持水平居中 */	
	background: #2b85e4;
	border-radius: 40rpx;
	font-size: 30rpx;
	margin-bottom: 25rpx;
	}
</style>